<?php
use think\Db;

/**
 * 获取省份
 * @param $region_id
 * @return mixed
 */
function get_province(){
    return Db::name('region')->where('region_type',1)->select();
}
//获取城市
function get_region($region_id){
    return Db::name('region')->where('parent_id',$region_id)->select();
}
/**
 * 获取科室
 */
function get_subject(){
    return Db::name('subject')->select();
}

/**
 * 获取医院
 */
function get_hospital($region_id){
    return Db::name('hospital')->where('region_id',$region_id)->select();
}

/**
 * 模拟提交数据，获得返回值
 */
function https_request($url, $data = null)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    if (!empty($data)) {
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($curl);
    curl_close($curl);
    return $output;
}
/**
 * 操作错误返回的快捷方法
 * @access protected
 * @param string $message 错误信息
 * @param integer $status 错误状态值
 * @return json
 */
function restError($message = '', $code = 0) {
    $return['code'] =   $code;
    $return['msg'] =   $message;
    return json($return, 200);
}

/**
 * 操作成功跳返回的快捷方法
 * @access protected
 * @param string $message 成功信息
 * @return json
 */
function restSuccess($message = '',$data = '') {
    $return['code'] =   1;
    $return['msg']  =   $message;
    $return['data'] =   $data;
    return json($return, 200);
}
